package com.fivetalks.client;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class DBConnect {
	
	public DBConnect(Context c){
		openhelper = new DBHelper(c);
		sdb = openhelper.getWritableDatabase();
	}
	
	public static DBConnect open(Context c) throws SQLException{
		DBConnect dh = new DBConnect(c);
		return dh;
	}
	
	public void close(){
		openhelper.close();
	}
	
	public long InsertDB(long id, String email, String nickname){
		
	//	sdb = openhelper.getWritableDatabase();
		ContentValues values = new ContentValues();
		values.put("id", id);
		values.put("email", email);
		values.put("nickname", nickname);
		long result = sdb.insert("MATCH_TB", null, values);
	//	sdb.close();
		return result;
	}
	
	public Cursor SelectDB() throws SQLException{
		
		Cursor cursor = sdb.rawQuery("SELECT * FROM MATCH_TB" , null);
	//	sdb.close();
		return cursor;
	}
	
	
	
	
	//수정을 위해 해당 값 select
	public Cursor selectDBWhere(long id) throws SQLException{
		Cursor cursor = sdb.rawQuery("SELECT * FROM MATCH_TB WHERE id = '"+id+"'", null);
		return cursor;
	}
	
	public void DeleteDB(long id){
		sdb.execSQL("DELETE FROM MATCH_TB WHERE id='" + id + "'");
	}
	
	public int countSelect() throws SQLException{
		Cursor cursor = sdb.rawQuery("SELECT * FROM MATCH_TB" , null);
		return cursor.getColumnCount();
	}
	
	public DBHelper openhelper;
	public SQLiteDatabase sdb;
	
}
